from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-15 14:03:44.707508
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 15, Jan, 2022
Time: 14:03:49
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.7134
Nobs: 537.000 HQIC: -48.1507
Log likelihood: 6236.19 FPE: 9.25511e-22
AIC: -48.4317 Det(Omega_mle): 7.83907e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.369737 0.071114 5.199 0.000
L1.Burgenland 0.103591 0.042821 2.419 0.016
L1.Kärnten -0.113222 0.022133 -5.115 0.000
L1.Niederösterreich 0.189121 0.089092 2.123 0.034
L1.Oberösterreich 0.114010 0.088658 1.286 0.198
L1.Salzburg 0.265536 0.045253 5.868 0.000
L1.Steiermark 0.028338 0.059604 0.475 0.634
L1.Tirol 0.105691 0.048054 2.199 0.028
L1.Vorarlberg -0.075548 0.042501 -1.778 0.075
L1.Wien 0.019093 0.078318 0.244 0.807
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.062631 0.155461 0.403 0.687
L1.Burgenland -0.042891 0.093610 -0.458 0.647
L1.Kärnten 0.040327 0.048385 0.833 0.405
L1.Niederösterreich -0.205571 0.194763 -1.055 0.291
L1.Oberösterreich 0.452835 0.193815 2.336 0.019
L1.Salzburg 0.285943 0.098927 2.890 0.004
L1.Steiermark 0.111747 0.130300 0.858 0.391
L1.Tirol 0.307401 0.105051 2.926 0.003
L1.Vorarlberg 0.021379 0.092912 0.230 0.818
L1.Wien -0.024647 0.171209 -0.144 0.886
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.194838 0.036319 5.365 0.000
L1.Burgenland 0.091730 0.021869 4.194 0.000
L1.Kärnten -0.007666 0.011304 -0.678 0.498
L1.Niederösterreich 0.234541 0.045501 5.155 0.000
L1.Oberösterreich 0.166663 0.045279 3.681 0.000
L1.Salzburg 0.039879 0.023111 1.726 0.084
L1.Steiermark 0.025630 0.030441 0.842 0.400
L1.Tirol 0.081966 0.024542 3.340 0.001
L1.Vorarlberg 0.054662 0.021706 2.518 0.012
L1.Wien 0.119336 0.039998 2.984 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.121401 0.036400 3.335 0.001
L1.Burgenland 0.042671 0.021918 1.947 0.052
L1.Kärnten -0.014223 0.011329 -1.255 0.209
L1.Niederösterreich 0.172153 0.045602 3.775 0.000
L1.Oberösterreich 0.333268 0.045380 7.344 0.000
L1.Salzburg 0.102696 0.023163 4.434 0.000
L1.Steiermark 0.109990 0.030509 3.605 0.000
L1.Tirol 0.091379 0.024597 3.715 0.000
L1.Vorarlberg 0.057045 0.021755 2.622 0.009
L1.Wien -0.016884 0.040087 -0.421 0.674
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107211 0.068963 1.555 0.120
L1.Burgenland -0.040397 0.041526 -0.973 0.331
L1.Kärnten -0.045477 0.021464 -2.119 0.034
L1.Niederösterreich 0.142313 0.086398 1.647 0.100
L1.Oberösterreich 0.173115 0.085977 2.014 0.044
L1.Salzburg 0.278899 0.043884 6.355 0.000
L1.Steiermark 0.063530 0.057801 1.099 0.272
L1.Tirol 0.153470 0.046601 3.293 0.001
L1.Vorarlberg 0.094989 0.041216 2.305 0.021
L1.Wien 0.076331 0.075949 1.005 0.315
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.086796 0.053571 1.620 0.105
L1.Burgenland 0.021448 0.032258 0.665 0.506
L1.Kärnten 0.052184 0.016673 3.130 0.002
L1.Niederösterreich 0.190125 0.067115 2.833 0.005
L1.Oberösterreich 0.327393 0.066788 4.902 0.000
L1.Salzburg 0.037980 0.034090 1.114 0.265
L1.Steiermark -0.001810 0.044901 -0.040 0.968
L1.Tirol 0.123730 0.036200 3.418 0.001
L1.Vorarlberg 0.064147 0.032017 2.004 0.045
L1.Wien 0.099327 0.058998 1.684 0.092
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.163539 0.064909 2.520 0.012
L1.Burgenland 0.009249 0.039085 0.237 0.813
L1.Kärnten -0.065438 0.020202 -3.239 0.001
L1.Niederösterreich -0.111734 0.081319 -1.374 0.169
L1.Oberösterreich 0.220786 0.080923 2.728 0.006
L1.Salzburg 0.050737 0.041304 1.228 0.219
L1.Steiermark 0.254058 0.054404 4.670 0.000
L1.Tirol 0.496856 0.043862 11.328 0.000
L1.Vorarlberg 0.064796 0.038793 1.670 0.095
L1.Wien -0.078892 0.071484 -1.104 0.270
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.163886 0.071805 2.282 0.022
L1.Burgenland -0.008226 0.043237 -0.190 0.849
L1.Kärnten 0.062514 0.022348 2.797 0.005
L1.Niederösterreich 0.175095 0.089958 1.946 0.052
L1.Oberösterreich -0.066186 0.089520 -0.739 0.460
L1.Salzburg 0.207690 0.045693 4.545 0.000
L1.Steiermark 0.137768 0.060183 2.289 0.022
L1.Tirol 0.055671 0.048521 1.147 0.251
L1.Vorarlberg 0.144215 0.042914 3.361 0.001
L1.Wien 0.130521 0.079079 1.651 0.099
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.394133 0.041964 9.392 0.000
L1.Burgenland -0.002245 0.025269 -0.089 0.929
L1.Kärnten -0.020692 0.013061 -1.584 0.113
L1.Niederösterreich 0.202477 0.052574 3.851 0.000
L1.Oberösterreich 0.240275 0.052318 4.593 0.000
L1.Salzburg 0.034620 0.026704 1.296 0.195
L1.Steiermark -0.016630 0.035173 -0.473 0.636
L1.Tirol 0.086663 0.028357 3.056 0.002
L1.Vorarlberg 0.050505 0.025080 2.014 0.044
L1.Wien 0.034518 0.046216 0.747 0.455
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.033228 0.097374 0.162157 0.136192 0.084931 0.079944 0.026197 0.208195
Kärnten 0.033228 1.000000 -0.027830 0.132551 0.047437 0.082676 0.446607 -0.071185 0.092746
Niederösterreich 0.097374 -0.027830 1.000000 0.305551 0.122541 0.262473 0.062767 0.155166 0.278323
Oberösterreich 0.162157 0.132551 0.305551 1.000000 0.216813 0.291426 0.166801 0.131209 0.231147
Salzburg 0.136192 0.047437 0.122541 0.216813 1.000000 0.125874 0.083993 0.106764 0.125700
Steiermark 0.084931 0.082676 0.262473 0.291426 0.125874 1.000000 0.134931 0.101725 0.025910
Tirol 0.079944 0.446607 0.062767 0.166801 0.083993 0.134931 1.000000 0.063172 0.146908
Vorarlberg 0.026197 -0.071185 0.155166 0.131209 0.106764 0.101725 0.063172 1.000000 -0.007776
Wien 0.208195 0.092746 0.278323 0.231147 0.125700 0.025910 0.146908 -0.007776 1.000000